package com.ling.pl;

import com.ling.pl.core.commons.exception.BusinessException;
import feign.Response;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Configuration;

/**
 * Created by bo.wang on 2017/4/10.
 * todo 网络异常由 ErrorDecoder 处理貌似没有运行
 * see ResposeInfoHttpMessageConverter
 */
@Configuration
public class LingErrorDecoder implements ErrorDecoder {
    @Override
    public Exception decode(String methodKey, Response response) {
        if (response.status() >= 400 && response.status() <= 499) {
            return new BusinessException("请求的服务路径错误或服务已经下线");
        }
        return feign.FeignException.errorStatus(methodKey, response);
    }
}
